package com.gyms.manager;

import android.content.Context;

import com.classic.okhttp.AppChangeUtils;
import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;

import utils.AppUtils;

/**
  * @desc:         统计中间处理类
  * @author:       Leo
  * @date:         2016/12/27
  */
public class StatisticsManager
{
    public static String UMENG_KEY = AppChangeUtils.UMENG_KEY;

    public static String HomePage_Search = "HomePage_Search_Click";
    public static String HomePage_Find = "HomePage_Find_Click";
    public static String HomePage_Button = "HomePage_Button_Click";
    public static String HomePage_SportsTag = "HomePage_SportsTag_Click";
    public static String VenueList_Sports = "VenueList_Sports_Click";
    public static String VenueList_TimeSelect = "VenueList_TimeSelect_Click";
    public static String VenueList_Area = "VenueList_Area_Click";
    public static String SiteDetail_Date = "SiteDetail_Date_Click";
    public static String Course_Search = "Course_Search_Click";
    public static String Course_PreferentialCourse = "Course_PreferentialCourse_Click";
    public static String Course_All = "Course_All_Click";
    public static String OrderDetail_Card = "OrderDetail_Card_Click";
    public static String OrderDetail_Pay = "OrderDetail_Pay_Click";
    public static String OrderDetail_Code = "OrderDetail_Code_Click";
    public static String MyCard_Add = "MyCard_Add_Click";
    public static String HomePage_banner = "HomePage_banner_Click";
    public static String Course_Banner = "Course_Banner_Click";

    private static StatisticsManager instance;

    public static StatisticsManager getInstance()
    {
        if (instance == null) {
            synchronized (StatisticsManager.class) {
                if (instance == null) {
                    instance = new StatisticsManager() ;
                }
            }
        }
        return instance;
    }

    /**
     * 初始化统计
     * @param context application的context
     */
    public void initUmeng(Context context)
    {
//        MobclickAgent.setDebugMode(!Cons.isRelease);//测试的就debug模式 防止污染数据
        MobclickAgent.setScenarioType(context, MobclickAgent.EScenarioType.E_UM_NORMAL);
        MobclickAgent.startWithConfigure(new MobclickAgent.UMAnalyticsConfig(
                context, UMENG_KEY, AppUtils.getPacketChannelName(context), MobclickAgent.EScenarioType.E_UM_NORMAL, true));
    }

    /**
     * 记录界面起始点
     * @param context  activity的context
     */
    public static void startActivity(Context context) {
        MobclickAgent.onResume(context);
        MobclickAgent.onPageStart(context.getClass().getName());
    }

    /**
     * 记录界面结束点
     * @param context  activity的context
     */
    public static void endActivity(Context context) {
        MobclickAgent.onPageEnd(context.getClass().getName());
        MobclickAgent.onPause(context);
    }

    /**
     * 上传定位
     * @param latitude   latitude
     * @param longitude  longitude
     */
    public static void setLocation(double latitude, double longitude) {
        MobclickAgent.setLocation(latitude, longitude);
    }

    /**
     * 统计事件点击次数
     * @param context  activity的context
     * @param eventId  事件名称
     */
    public static void onEvent(Context context, String eventId)
    {
        if (null == eventId) {
            return;
        }

        MobclickAgent.onEvent(context, eventId);
    }

    /**
     * 统计事件点击次数
     * @param context  activity的context
     * @param eventId  事件名称
     * @param label    事件子分类标签
     */
    public static void onEvent(Context context, String eventId, String label)
    {
        if (null == eventId) {
            return;
        }

        MobclickAgent.onEvent(context, eventId, label);
    }

    /**
     * 统计事件点击次数
     * @param context  activity的context
     * @param eventId  事件名称
     * @param attrMap  收集参数集合
     */
    public static void onEvent(Context context, String eventId, HashMap attrMap)
    {
        if (null == eventId || null == attrMap) {
            return;
        }

        MobclickAgent.onEvent(context, eventId, attrMap);
    }
}
